package com.xiaoshuidi.cloud.framework.filings.core.enums;

import cn.hutool.core.util.StrUtil;
import lombok.AllArgsConstructor;
import lombok.Getter;

import java.util.Arrays;
import java.util.Optional;

/**
 * 支付周期
 * @Author Feng
 * @date 2023/5/5
 */
@Getter
@AllArgsConstructor
public enum PaymentCycleEnum {

    ONE_ONE(1,"押一付一"),
    ONE_THREE(2,"押一付三"),
    TWO_THREE(3,"押二付三"),
    THREE_THREE(4,"押三付三"),
    ONE_SIX(5,"押一付六"),
    TWO_SIX(6,"押二付六"),
    THREE_SIX(7,"押三付六"),
    ONE_ONE_YEAR(8,"押一付一年"),
    TWO_ONE_YEAR(9,"押二付一年"),
    THREE_ONE_YEAR(10,"押三付一年"),
    ONE_TWO(11,"押一付二"),
    TWO_TWO(12,"押二付二"),
    THREE_TWO(13,"押三付二");

    private int code;
    private String name;

    public static Integer getCodeByName(String name) {
        if (StrUtil.isEmpty(name)) {
            return null;
        }
        Optional<PaymentCycleEnum> find = Arrays.stream(PaymentCycleEnum.values()).filter(s -> s.getName().equals(name)).findFirst();
        if (find.isPresent()) {
            return find.get().getCode();
        }
        return null;
    }
}